#ifndef CMESH_H_
#define CMESH_H_

#include "../math/cvector2d.h"
#include "../math/cvector3d.h"

struct TTriangle {
  static const TIndex NUM_OF_VERTS_TRIANGLE = 3;
  int vertIds[NUM_OF_VERTS_TRIANGLE];
  int coordIds[NUM_OF_VERTS_TRIANGLE];
};

/**
 * CMesh - class representing mesh (part of 3D model)
 * @author Michal Rost
 * @date 20.07.2007
 */
class CMesh : CObject {
public:
  CMesh();
  virtual ~CMesh();
  void setStrName(string strName);
  void setMaterialId(int materialId);
  string getStrName() const;
  int getMaterialId() const;
  int getNumOfVerts() const;
  int getNumOfCoords() const;
  int getNumOfFaces() const;
  CVector3D<float>* getVertsPtr() const;
  CVector2D<float>* getCoordsPtr() const;
  CVector3D<float>* getNormalsPtr() const;
  TTriangle* getFacesPtr() const;
  int* getIndicesPtr() const;
  CVector3D<float>* createVerts(int numOfVerts);
  CVector2D<float>* createCoords(int numOfCoords);
  TTriangle* createFaces(int numOfFaces);
  void computeNormals();
  void computeIndices();
  static string getClassName() {
    return "CMesh";
  }
protected:
  string strName;
  int materialId;
  int numOfVerts;
  int numOfCoords;
  int numOfFaces;
  CVector3D<float>* verts;
  CVector2D<float>* coords;
  CVector3D<float>* normals;
  TTriangle* faces;
  int* indices;
  void deleteVerts();
  void deleteCoords();
  void deleteFaces();
  void free();
};

#endif
